package com.rayc.mall.item.config;

import com.rayc.mall.item.properties.ESProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: Ray-C
 * @CreateTime: 2025-03-26
 * @Description: es配置类
 * @Version: 1.0
 */
@Slf4j
@Configuration
@RequiredArgsConstructor
public class ESConfig {
    private final ESProperties properties;

    @Bean
    public RestHighLevelClient elasticsearchClient() {
        RestClientBuilder rcb = RestClient.builder(new HttpHost(properties.getHost(), properties.getPort()));
        RestHighLevelClient client = new RestHighLevelClient(rcb);
        log.info("elasticsearch client started | host: {}, port: {}", properties.getHost(), properties.getPort());
        return client;
    }
}
